#!/bin/sh
#变量
echo "install……"
G_bb="170209_mips_"  #程序版本
G_kp="/usr/share/koolproxy"
G_ram="/tmp/G_RAM/koolproxy"
G_dizhi="https://git.oschina.net/g0g001/tmp_G_RAM/raw/master"
#
G_WJT=https://rules.ngrok.wang/koolproxy.txt
G_WJD=https://rules.ngrok.wang/1.dat
G_WJV=https://rules.ngrok.wang/config.json.js
#
#安装原版koolproxy.ipk
mkdir -p "$G_ram"
ln -s "$G_ram" "$G_kp"
wget -O /tmp/g_ram.ipk "$G_dizhi"/"$G_bb"koolproxy.ipk
wget -O /tmp/zh_ram.ipk "$G_dizhi"/"$G_bb"koolproxy-zh-cn.ipk
opkg update
opkg install /tmp/g_ram.ipk /tmp/zh_ram.ipk
rm /tmp/g_ram.ipk /tmp/zh_ram.ipk
#删除要优化的文件
rm -v "$G_ram"/koolproxy "$G_ram"/koolproxyupdate "$G_ram"/data/koolproxy.txt "$G_ram"/data/1.dat "$G_ram"/data/version "$G_ram"/data/certs/mozilla_cert.pem /usr/sbin/adblockplus /etc/init.d/koolproxy /etc/init.d/.koolproxy.swp
rm -rvf "$G_kp"
#用户文件放回ROM区
cp -pR "$G_ram" "$G_kp"
rm -rvf "$G_ram"
#下载程序基础包
wget -O /tmp/G_RAM.tar.gz "$G_dizhi"/"$G_bb"G_RAM.tar.gz
tar -zxpf /tmp/G_RAM.tar.gz -C /tmp/
wget -O "$G_ram"/koolproxy.txt "$G_WJT"
wget -O "$G_ram"/1.dat "$G_WJD"
wget -O "$G_ram"/version "$G_WJV"
rm /tmp/G_RAM.tar.gz
#创建必要软链接
ln -s "$G_ram"/koolproxy "$G_kp"/koolproxy
ln -s "$G_ram"/koolproxyupdate "$G_kp"/koolproxyupdate
ln -s "$G_ram"/koolproxy.txt "$G_kp"/data/koolproxy.txt
ln -s "$G_ram"/1.dat "$G_kp"/data/1.dat
ln -s "$G_ram"/version "$G_kp"/data/version
ln -s "$G_ram"/mozilla_cert.pem "$G_kp"/data/certs/mozilla_cert.pem
ln -s "$G_ram"/adblockplus /usr/sbin/adblockplus
ln -s "$G_ram"/init.d/koolproxy /etc/init.d/koolproxy
ln -s "$G_ram"/init.d/.koolproxy.swp /etc/init.d/.koolproxy.swp
#下载开机脚本和守护脚本
wget -O /bin/00kool.sh "$G_dizhi"/"$G_bb"00.sh
wget -O /bin/01kool.sh "$G_dizhi"/"$G_bb"01.sh
chmod +x /bin/00kool.sh
chmod +x /bin/01kool.sh
#添加开机启动
sed -i 's:exit 0::g' /etc/rc.local || sed -i 's:exit::g' /etc/rc.local
echo 'sh /bin/00kool.sh&' >> /etc/rc.local || echo -e "\n\n-----  Dai Ma 007   ------\n\n"
echo 'exit 0' >> /etc/rc.local
echo "----   OK  --  OK  --  OK  -----"
exit 0